<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>为 MIME 头编码字符串</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.mb-detect-order.html">« mb_detect_order</a></li>
      <li style="float: right;"><a href="function.mb-encode-numericentity.html">mb_encode_numericentity »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.mbstring.html">多字节字符串 函数</a></li>
    <li>为 MIME 头编码字符串</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.mb-encode-mimeheader" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mb_encode_mimeheader</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.6, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">mb_encode_mimeheader</span> &mdash; <span class="dc-title">为 MIME 头编码字符串</span></p>

 </div>
   
 <div class="refsect1 description" id="refsect1-function.mb-encode-mimeheader-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>mb_encode_mimeheader</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$string</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">?</span><span class="type"><span class="type">string</span><span class="type"></span></span> <code class="parameter">$charset</code><span class="initializer"> = <strong><code>null</code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">?</span><span class="type"><span class="type">string</span><span class="type"></span></span> <code class="parameter">$transfer_encoding</code><span class="initializer"> = <strong><code>null</code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$newline</code><span class="initializer"> = &quot;\r\n&quot;</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$indent</code><span class="initializer"> = 0</span></span><br>): <span class="type">string</span></div>

  <p class="para rdfs-comment">
   按 MIME 头编码方案将指定的<span class="type"><span class="type 字符串">字符串</span></span> <code class="parameter">string</code> 进行编码。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mb-encode-mimeheader-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">string</code></dt>

     <dd>

      <p class="para">
       要编码的 <span class="type">string</span>。
       它的编码应该和 <span class="function"><a href="function.mb-internal-encoding.html" class="function">mb_internal_encoding()</a></span> 一样。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">charset</code></dt>

     <dd>

      <p class="para">
       <code class="parameter">charset</code> 指定了 <code class="parameter">str</code> 的字符集名。
       其默认值由当前的 NLS 设置（<code class="literal">mbstring.language</code>）来确定。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">transfer_encoding</code></dt>

     <dd>

      <p class="para">
       <code class="parameter">transfer_encoding</code> 指定了 MIME 的编码方案。
       它可以是 <code class="literal">&quot;B&quot;</code>（Base64）也可以是 <code class="literal">&quot;Q&quot;</code>（Quoted-Printable）。
       如果未设置，将回退为 <code class="literal">&quot;B&quot;</code>。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">newline</code></dt>

     <dd>

      <p class="para">
       <code class="parameter">newline</code> 指定了 EOL（行尾）标记，使 <span class="function"><strong>mb_encode_mimeheader()</strong></span> 执行了一个换行（<a href="http://www.faqs.org/rfcs/rfc2822" class="link external">&raquo;&nbsp;RFC</a> 文档中规定，超过长度的一行将换成多行，当前该长度硬式编码为 74 个字符）。
       如果没有设定，则回退为 <code class="literal">&quot;\r\n&quot;</code> (CRLF)。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">indent</code></dt>

     <dd>

      <p class="para">
       首行缩进（header 里 <code class="parameter">string</code> 前的字符数目）。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.mb-encode-mimeheader-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   转换后的<span class="type"><span class="type 字符串">字符串</span></span>版本以 ASCII 形式表达。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.mb-encode-mimeheader-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">charset</code> 和 <code class="parameter">transfer_encoding</code>
       现在可以为空。
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.mb-encode-mimeheader-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2568">
    <p><strong>示例 #1 <span class="function"><strong>mb_encode_mimeheader()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$name&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"太郎"</span><span style="color: #007700">;&nbsp;</span><span style="color: #FF8000">//&nbsp;kanji<br /></span><span style="color: #0000BB">$mbox&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"kru"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$doma&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"gtinn.mon"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$addr&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'"'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">addcslashes</span><span style="color: #007700">(</span><span style="color: #0000BB">mb_encode_mimeheader</span><span style="color: #007700">(</span><span style="color: #0000BB">$name</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"UTF-7"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Q"</span><span style="color: #007700">),&nbsp;</span><span style="color: #DD0000">'"'</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">'"&nbsp;&lt;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$mbox&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"@"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$doma&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"&gt;"</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #0000BB">$addr</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
     <div class="cdata"><pre>
&quot;=?UTF-7?Q?+WSqQzg-?=&quot; &lt;kru@gtinn.mon&gt;
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.mb-encode-mimeheader-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    这个函数没有设计成据更高级上下文的中断点来换行（单词边界等）。
    这个特性将导致意外的空格可能会让原始字符串看上去很乱。
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mb-encode-mimeheader-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.mb-decode-mimeheader.html" class="function" rel="rdfs-seeAlso">mb_decode_mimeheader()</a> - 解码 MIME 头字段中的字符串</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>